<!DOCTYPE html>
<html lang='en'>
<head>
  <meta charset='UTF-8'>
  <meta name='viewport' content='width=device-width, initial-scale=1.0'>
  <title></title>
  <script type='text/javascript' src='js/vue.js'></script>
</head>
<body>
  <div id='app'>
    <div>
      <label for="uname">用户名</label>
      <input type="text" name="uname" v-model.lazy="uname">
      <span>{{msg}}</span>
    </div>
  </div>
  <script type='text/javascript'>
    var vm = new Vue({
      el: '#app',
      data: {
       uname: '',
       msg: ''
      },
      methods: {
        checkUname(val){
          this.msg = '后台检测中...'
          setTimeout(()=>{
            if(val === 'admin' ) {
              this.msg = '用户名重复，请重新选择用户名'
            }else {
              this.msg = '恭喜您，此用户名可用'
            }
          },2000)
        }
      },
      watch: {
        uname: function(val, oldVal) {
          this.checkUname(val);
        }
      },
    });
  </script>
</body>
</html>